package com.network.chatsoft.controller;

import com.network.chatsoft.entity.R;
import com.network.chatsoft.entity.UserEntity;
import com.network.chatsoft.service.UserService;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
public class UserController {

    @Resource
    UserService userService;


    @GetMapping("/login")
    public String login() {return "login";}

    @GetMapping("/chat")
    public String chat()
    {
        return "chat";
    }
    @GetMapping("/register")
    public String register(){return "register";}

    @PostMapping("/login")
    @ResponseBody
    public R<UserEntity> login(@Param("username") String username, @Param("password") String password, HttpSession session){
        R<UserEntity> login = userService.login(username, password, session);
        System.out.println(session.getAttribute("username"));
        return login;
    }

    @PostMapping("/regist")
    @ResponseBody
    public R<String> regist(String username,String password){
        return userService.regist(username,password);
    }
}
